package com.briup.jz.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.briup.jz.bean.OrderLine;
import com.briup.jz.bean.OrderLineExample;
import com.briup.jz.dao.OrderLineMapper;
import com.briup.jz.service.IOrderLineService;
import com.briup.jz.utils.CustomerException;

import io.swagger.annotations.Example;
@Service
public class OrderLineServiceImpl implements IOrderLineService{
	@Autowired
	private OrderLineMapper orderLineMapper;
	
	@Override
	public void savaOrUpdate(OrderLine orderLine) throws CustomerException {
		 OrderLineExample example=new OrderLineExample();
	        if (orderLine.getId()!=null){
//	            判断用户是否输入主键信息
	            orderLineMapper.updateByPrimaryKey(orderLine);
	        }else {
//	            判断有id 的订单项是否为空
	            OrderLine orderLine1= orderLineMapper.selectByPrimaryKey(orderLine.getId());

	            if (orderLine1==null){
	                //            如果为空则为插入操作
	                orderLineMapper.insert(orderLine);
	            }
	           

	        }
	    }

	@Override
	public List<OrderLine> query(Long id, Long productID, Long orderId) {
        OrderLineExample example =new OrderLineExample();
        if (id!=null){
//            如果主键不为空则按照主键查询
            example.createCriteria().andIdEqualTo(id);
        }
        if (productID!=null){
//            判断产品id是否为空,如果不为空则按照产品id 查询
            example.createCriteria().andProductIdEqualTo(productID);
        }
        if (orderId!=null){
//            判断订单id是否为空,如果不为空则按照订单号查询
            example.createCriteria().andOrderIdEqualTo(orderId);
        }
//        按照条件查寻
        return orderLineMapper.selectByExample(example);
    }

	@Override
	public void deleteById(long id) throws CustomerException {
		OrderLine orderLine =orderLineMapper.selectByPrimaryKey(id);
		if(orderLine == null) {
			throw new CustomerException("要删除的分类信息不存在");
		}
		orderLineMapper.deleteByPrimaryKey(id);
	}

}


